const storageConfig = JSON.parse(localStorage.getItem("layout-setting")) || {};
/**
 * 定义应用的状态
 */
const state = {
  // 网页标题
  title: "",
  // 启用动态标题
  dynamicTitle: true,
};

/**
 * 定义修改状态的方法
 */
const mutations = {
  // 修改标题
  setTitle(state, title) {
    state.title = title;
  },
  // 修改布局设置
  CHANGE_SETTING: (state, { key, value }) => {
    if (state.hasOwnProperty(key)) {
      state[key] = value;
    }
  },
};
/**
 * 定义触发mutations的动作方法
 */
const actions = {
  // 修改标题
  updateTitle({ commit }, title) {
    commit("setTitle", title);
  },
  // 修改布局设置
  changeSetting({ commit }, data) {
    commit("CHANGE_SETTING", data);
  },
};
/**
 * 定义获取状态的方法
 */
const getters = {
  title: (state) => state.title,
  dynamicTitle: (state) => state.dynamicTitle,
};

export default {
  namespaced: true,
  state,
  mutations,
  actions,
  getters,
};
